// pages/customer/customerManagerDetail.js
import { datetimeFormat } from "../../utils/util";
const reg = /^(\d{3})\d{4}(\d{4})$/;

Page({

    /**
     * 页面的初始数据
     */
    data: {
        customerManager: [
            {
                id: 1,
                name: 'liucs',
                customer: '中海油湖南销售有限公司',
                phone: '13566768678',
                createDate: 1676278924000,
                remarks: '',
                num: 500,
                price: 15000000
            },
            {
                id: 2,
                name: '测试',
                customer: '中海油湖南销售有限公司1',
                phone: '13566768678',
                createDate: 1676277654000,
                remarks: '',
                num: 500,
                price: 15000000
            },
            {
                id: 3,
                name: '测试1',
                customer: '中海油湖南销售有限公司2',
                phone: '13566768678',
                createDate: 1675155724000,
                remarks: '',
                num: 500,
                price: 15000000
            },
            {
                id: 4,
                name: '测试2',
                customer: '中海油湖南销售有限公司3',
                phone: '13566768678',
                createDate: 1673600524000,
                remarks: '',
                num: 500,
                price: 15000000
            },
            {
                id: 5,
                name: '测试',
                customer: '中海油湖南销售有限公司4',
                phone: '13566768678',
                createDate: 16762789220952,
                remarks: '',
                num: 100,
                price: 300000
            },
            {
                id: 6,
                name: '测试1',
                customer: '中海油湖南销售有限公司5',
                phone: '13566768678',
                createDate: 1676277654000,
                remarks: '',
                num: 200,
                price: 600000
            },
            {
                id: 7,
                name: '测试2',
                customer: '中海油湖南销售有限公司6',
                phone: '13566768678',
                createDate: 1676277654000,
                remarks: '',
                num: 400,
                price: 12000000
            },
        ],
        id: null,
        customerManagerS: {},
        flag: false,

        show: false,
        duration: 300,
        position: 'bottom',
        round: false,
        overlay: true,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.data.id = options.id;
        this.getCustomerManager();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    onClickHidePhone() {
        let flag = !this.data.flag;
        this.setData({
            flag: flag
        })
    },

    getCustomerManager() {
        for (let i = 0; i < this.data.customerManager.length; i++) {
            this.data.customerManager[i].hidePhone = this.data.customerManager[i].phone.replace(reg, '$1****$2');
        }
        this.setData({
            customerManager: this.data.customerManager
        })
        this.data.customerManager.forEach(item => {
            console.log(item);
            if (this.data.id == item.id) {
                this.data.customerManagerS = item;
                this.data.customerManagerS.createDate = datetimeFormat(this.data.customerManagerS.createDate);
                this.data.customerManagerS.price = this.toThousands(this.data.customerManagerS.price);
                this.setData({
                    customerManagerS: this.data.customerManagerS
                })
            }
        })
    },
    delChange() {
        let id = this.data.id;
        let customerManager = this.data.customerManager;
        let _this = this;
        wx.showModal({
            title: '提示',
            content: '确认删除?',
            success(res) {
                if (res.confirm) {
                    //删除接口
                } else if (res.cancel) {
                    return false
                }
            }
        });
    },
    editChange() {
        this.setData({
            show:true,
        })
    },
    onClickOverlay(){
        this.setData({
            show:false
        })
    },
    clearChange(){
        this.setData({
            show:false
        })
    },
    confirmChange(){
        this.setData({
            show:false
        })
    },
    //格式化金额千分位
    toThousands(num) {
        return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
    }
})